package com.huawei.appgallery.foundation.ui.framework.cardframe.fragment;

import android.app.Activity;
import android.os.AsyncTask.Status;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import com.huawei.appgallery.foundation.ui.framework.uikit.ContractFragment;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import o.cfw;
import o.cjo;
import o.cvt;
import o.BaseRequest;
import o.AsyLoader;
import o.dgm;
import o.dmi;
import o.dmq;
import o.Logger;
import o.ActivityUtil;
import o.FragmentManager;
import o.FragmentTransaction;

public abstract class TaskFragment<T extends cjo> extends ContractFragment<T> {
    private e ˊ;
    private List<cvt> ˋ;
    private int ˎ = 0;
    private boolean ॱ = false;
    protected AsyLoader ᶥॱ;

    public interface e {
        boolean ˋ(TaskFragment taskFragment, b bVar);

        void ˎ(TaskFragment taskFragment, List<cvt> list);
    }

    public static class a implements IServerCallBack {
        private WeakReference<TaskFragment> ˎ;

        public a(TaskFragment taskFragment) {
            this.ˎ = new WeakReference(taskFragment);
        }

        public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
        }

        public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
            if (this.ˎ != null) {
                TaskFragment taskFragment = (TaskFragment) this.ˎ.get();
                if (taskFragment != null) {
                    int i;
                    boolean ˊ = taskFragment.ˊ(taskFragment, new b(o_cvu, responseBean));
                    String str = "TaskFragment";
                    StringBuilder append = new StringBuilder("notifyResult, bContinue: ").append(ˊ).append(",requestQueue.size: ");
                    if (taskFragment.ˋ == null) {
                        i = 0;
                    } else {
                        i = taskFragment.ˋ.size();
                    }
                    Logger.ˎ(str, append.append(i).append(",currentRequestIndex: ").append(taskFragment.ˎ).toString());
                    if (ˊ) {
                        taskFragment.ˎ = taskFragment.ˎ + 1;
                        i = taskFragment.ˎ;
                        List ˎ = taskFragment.ˋ;
                        if (ˎ != null && ˎ.size() > i) {
                            taskFragment.ᶥॱ = cfw.ˎ((cvt) ˎ.get(i), this);
                            return;
                        }
                        return;
                    }
                    taskFragment.ˎ = 0;
                    return;
                }
                Logger.e("TaskFragment", "ServerCallBackImpl, notifyResult, taskFragment == null");
            }
        }
    }

    public static class b {
        public BaseRequest ˊ;
        public ResponseBean ˋ;

        public b(BaseRequest o_cvu, ResponseBean responseBean) {
            this.ˊ = o_cvu;
            this.ˋ = responseBean;
        }
    }

    public static class c implements dmi {
        private WeakReference<AsyLoader> ˊ;

        public c(AsyLoader o_cwa) {
            this.ˊ = new WeakReference(o_cwa);
        }

        public void run() {
            if (this.ˊ == null) {
                Logger.ˎ("TaskFragment", "Block run, dismiss, serverTask is null");
                return;
            }
            AsyLoader o_cwa = (AsyLoader) this.ˊ.get();
            if (o_cwa == null) {
                Logger.ˎ("TaskFragment", "Block run, dismiss, task is null");
            } else if (o_cwa.getStatus() != Status.FINISHED) {
                o_cwa.ˎ(true);
            }
        }
    }

    public boolean ʼʻ() {
        return this.ॱ;
    }

    public void ॱˋ(boolean z) {
        this.ॱ = z;
    }

    protected e ʼʼ() {
        return this.ˊ;
    }

    public void ˊ(e eVar) {
        this.ˊ = eVar;
    }

    public TaskFragment ˋ(FragmentManager juVar, int i, String str) {
        FragmentTransaction ˊ = juVar.ˊ();
        Fragment findFragmentByTag = juVar.findFragmentByTag(str);
        if (findFragmentByTag != null) {
            try {
                ˊ.ˏ(findFragmentByTag);
            } catch (Exception e) {
                Logger.e("TaskFragment", "show fragment appers IllegalStateException.");
            }
        } else {
            ˊ.ˏ(i, this, str);
        }
        ˊ.ˋ();
        return this;
    }

    public void ॱ(FragmentManager juVar) {
        if (ActivityUtil.isAcitivtyNotValid(ॱˋ())) {
            Logger.e("TaskFragment", "dismiss, activity is destroyed");
            return;
        }
        FragmentTransaction ˊ = juVar.ˊ();
        if (ˊ != null) {
            ˊ.ॱ((Fragment) this);
            ˊ.ˋ();
            return;
        }
        Logger.e("TaskFragment", "dismiss, ft is null");
    }

    public void ˏ(Bundle bundle) {
        c_(true);
        super.ˏ(bundle);
        ʾˊ();
        if (this.ॱ) {
            Logger.ˎ("TaskFragment", "onCreate, isDataReadyFlag: " + this.ॱ);
        }
    }

    protected void ʾˊ() {
        ʾˋ();
    }

    public void ʾˋ() {
        if (!this.ॱ) {
            ʿˊ();
        }
    }

    public void ʾᐝ() {
        if (this.ᶥॱ != null) {
            this.ᶥॱ.ˎ(true);
        }
    }

    public void ˎˎ() {
        ʽʽ();
        super.ˎˎ();
    }

    protected void ʽʽ() {
        dmq.ˏ.ॱ(new c(this.ᶥॱ));
    }

    public void ॱ(Activity activity) {
        super.ॱ(activity);
        if (activity instanceof e) {
            this.ˊ = (e) activity;
        }
    }

    public void ʿˊ() {
        this.ˋ = new ArrayList();
        ˋ(this, this.ˋ);
        Logger.ˎ("TaskFragment", "excute, size: " + this.ˋ.size() + ", currentRequestIndex: " + this.ˎ);
        if (this.ˋ.size() > this.ˎ) {
            cvt o_cvt = (cvt) this.ˋ.get(this.ˎ);
            if (ॱˋ() != null) {
                o_cvt.setServiceType_(dgm.ˎ(ॱˋ()));
            }
            this.ᶥॱ = cfw.ˊ(o_cvt, new a(this));
        }
    }

    public boolean ˊ(TaskFragment taskFragment, b bVar) {
        if (this.ˊ != null) {
            return this.ˊ.ˋ(taskFragment, bVar);
        }
        Logger.e("TaskFragment", "onCompleted, mExcuteListener == null");
        return false;
    }

    public void ˋ(TaskFragment taskFragment, List<cvt> list) {
        if (this.ˊ != null) {
            this.ˊ.ˎ(taskFragment, list);
        } else {
            Logger.ˋ("TaskFragment", "onPrepareRequestParams, mExcuteListener == null");
        }
    }
}
